package com.qiujie.controller;

import com.qiujie.dto.ResponseDTO;
import com.qiujie.service.AnnualLeaveService;
import com.qiujie.vo.AnnualLeaveVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/annual-leave")
public class AnnualLeaveController {

    @Autowired
    private AnnualLeaveService service;

    @ApiOperation("获取剩余年休假")
    @GetMapping("/remaining")
    public ResponseDTO getRemaining(@RequestParam Integer staffId) {
        return service.getRemainingDays(staffId);
    }

    @ApiOperation("调整年休假额度")
    @PutMapping("/adjust")
    @PreAuthorize("hasAuthority('performance:annual:adjust')")
    public ResponseDTO adjust(@RequestBody AnnualLeaveVO vo) {
        return service.adjustAnnualLeave(vo.getStaffId(), vo.getAdjustDays());
    }

    @ApiOperation("申请年休假")
    @PostMapping("/apply")
    @PreAuthorize("hasAuthority('leave:annual:apply')")
    public ResponseDTO applyAnnualLeave(@RequestBody Map<String,Object> params) {
        return service.deductAnnualLeave(
                (Integer) params.get("staffId"),
                (Integer) params.get("days")
        );

    }
}


